<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.lp.cfg.ProConfig"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
	<title><%=ProConfig.PROJECT_NAME %></title>
	<%@ include file="/WEB-INF/wechat/iot/common/resource_lib.jsp"%>
	<style type="text/css">
		.sub-container{
			margin-left: 10px;
			padding: 10px 10px 10px 0;
			border-top: 1px solid #d9d9d9;
		}
		
		.sub-container:FIRST-CHILD{
			border-top: 0;
		}
		
		.body-container{
			background: #fff ;
		}
		.sub-container p{
			font-size: 14px;
		}
	</style>
</head>
<body>
	<div class="container">
		<div class="t-c title-info">
			<span>Subaccount list</span>
			<div class="back" onclick="forward('/wiot/user')" style=" position: fixed;top: 0px;" >Back</div>
			<c:if test="${user.type != 7 }">
				<div class="add" onclick="forward('/wiot/eaccount')" style=" position: fixed;top: 0px;right: 10px;" >Add</div>
			</c:if>
		</div>
		<div style="height: 50px;"></div>
		
		<div class="body-container">
			
		</div>
		<%@ include file="/WEB-INF/wechat/iot/common/pager.jsp"%>
	</div>
	<div class="hide" id="template">
		<div class="sub-container clear" onclick="subAccountInit({id})">
			<div class="float-left width50">
				<p class="title" style="color: #333;">
					<span>{name}</span>
					<span class="{style}">{data.status}</span>
				</p>
				<p style="color: #aaa;padding-top: 10px;">{phone}</p>
			</div>
			<div class="float-left width50 " style="text-align: right;">
				<p style="color: #aaa;">
					{data.type}
				</p>
				<p style="color: #666;padding-top: 10px;">Number of entries：{scene_num}</p>
			</div>
		</div>
	</div>
	
</body>
<script type="text/javascript">
	
	function subAccountInit(id){
		$.actions({
			  actions: [{
				    text: "accredit",
				    className: "color-warning",
				    onClick: function() {
				    	forward("/wiot/gaccount?id="+id);
				    }
				  },{
			    text: "editor",
			    className: "color-success",
			    onClick: function() {
			     	forward("/wiot/eaccount?id="+id);
			    }
			  },
			  {
			    text: "delete",
			    className: "color-danger",
			    onClick: function() {
			    	$.confirm("Do you confirm deletion?", function() {
			    		commonAjax("DELETE",localUrl+"/user/info?id="+id, "",function(){
							tip("Successfully deleted");
							window.location.reload();
						});
					  }, function() {
					  
					  });
			    }
			  }]
			});
	}
	
	$(function(){
	
		function getData(n){
			postAjax(localUrl+"/page/user.json?paged="+n, data,function(data){
				if(isOK(data)){
					var dataT = data.data.data ;
					for(var i=0;i<dataT.length;i++){
						if(dataT[i].status == 60 ){
							dataT[i].style = 'state';
						}else if(dataT[i].status == 61){
							dataT[i].style = 'state-red';
						}else if(dataT[i].status == 59){
							dataT[i].style = 'state-default';
						}
						dataT[i].atimestr = time2Str(dataT[i].atime);
						$(".body-container").append( $("#template").html().format(dataT[i]));					
					}
					
					if(data.data.totalPage > data.data.paged){
						loading = false;						
					}else{
						loading =true ;	
					}
				}else{
					loading =true ;	
				}
				// 传data就可以，分页的
				pagerinit(data,".body-container");
			});	
		}
		
		// 查询条件
		var data = { aid:'${user.id}' , scene_num_flag:1 } ;
		var paged = 1;
		getData(paged++);
		var loading = false;  //状态标记
		$(document.body).infinite().on("infinite", function() {
			if (loading)
				return;
			loading = true;
			setTimeout(function() {
				// 获取商品信息
				getData(paged++);
			}, 500); 
		});
		
	})
	
	
</script>
</html>